package org.smart4j.framework.proxy;

import java.lang.reflect.Method;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.smart4j.framework.annotation.Aspect;
import org.smart4j.framework.annotation.Controller;

/**
 * 拦截Controller所有方法<br>
 *
 * @author andy
 * @version V1.0
 * @date 18/1/31 下午3:53
 */
@Aspect(Controller.class)
public class ControllerAspect extends AspectProxy{

    private static final Logger LOG = LoggerFactory.getLogger(ControllerAspect.class);

    private long begin;

    @Override
    public void before(Class<?> cls, Method method, Object[] params) {
        LOG.debug("---------begin-----------");
        LOG.debug("class : {}", cls.getName());
        LOG.debug("method : {}", method.getName());
        begin = System.currentTimeMillis();
    }

    @Override
    public void after(Class<?> cls, Method method, Object[] params, Object result) {
        LOG.debug("time : {}", System.currentTimeMillis() - begin);
        LOG.debug("---------end-----------");
    }
}
